package com.fenghongzhang.lib_core.utils

import android.Manifest
import android.app.Activity
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.database.Cursor
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.Point
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.location.LocationManager
import android.net.Uri
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.provider.MediaStore
import android.provider.Settings
import android.text.Editable
import android.text.TextWatcher
import android.util.TypedValue
import android.view.View
import android.view.WindowManager
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.text.isDigitsOnly
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.paging.PagingConfig


import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.onFailure
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow

import java.io.File
import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.reflect.Field
import java.lang.reflect.InvocationTargetException
import java.util.regex.Pattern
import kotlin.random.Random

fun tintDrawable(drawable: Drawable?, colors: Int): Drawable? {
    val wrappedDrawable = DrawableCompat.wrap(drawable!!).mutate()
    DrawableCompat.setTint(wrappedDrawable, colors)
    return wrappedDrawable
}


//获取属性值
fun getAttrValue(context: Context, attrId: Int): Int {
    val typedValue = TypedValue()
    context.theme.resolveAttribute(attrId, typedValue, true)
    return typedValue.resourceId
}

fun getVersionCode(mContext: Context): Int {
    var versionCode = 0
    try {
        //获取软件版本号，对应AndroidManifest.xml下android:versionCode
        versionCode = mContext.packageManager.getPackageInfo(mContext.packageName, 0).versionCode
    } catch (e: PackageManager.NameNotFoundException) {
        e.printStackTrace()
    }
    return versionCode
}

//全局分页的配置
const val DEFAULT_PAGE_SIZE = 10
const val INITIAL_LOAD_SIZE = 10
val globalPagingConfig: PagingConfig
    get() {

        return PagingConfig(
            pageSize = DEFAULT_PAGE_SIZE,
            enablePlaceholders = true,
            initialLoadSize = INITIAL_LOAD_SIZE,
            prefetchDistance = DEFAULT_PAGE_SIZE
        )
    }

fun View.setLandscape() {
    val l = layoutParams
    l.width = 343
    l.height = 180
    layoutParams = l
}

fun View.setPortrait() {
    val l = layoutParams
    l.width = 233
    l.height = 311
    layoutParams = l
}
//阿里云-获取视频首帧图片
fun getAliOSSVideoImage(videoUrl: String): String {
    return "$videoUrl&x-oss-process=video/snapshot,t_1,f_jpg,ar_auto"
}
